package com.bootdo.system.controller;

import com.bootdo.app.service.BackGroundService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.TbWxBackGround;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @create 2021-03-06 19-59
 */
@Api("后台背景图片")
@Controller
@RequestMapping("/system/backgroud")
public class BackGroudController {

    @Autowired
    private BackGroundService backGroundService;

    @GetMapping("")
    public String result(){
        return "system/background/background";
    }

    @GetMapping("/ed/{id}")
    public String edit(@PathVariable long id, Model model){
        TbWxBackGround map = backGroundService.selectById(id);
        model.addAttribute("wx",map);
        model.addAttribute("wc",map.getWxBackGround());
        return "system/background/edit";
    }

    @GetMapping("ad")
    public String add(){
        return "system/background/add";
    }

    @GetMapping("/list")
    @ResponseBody
    public PageUtils selectBackGroundList(@RequestParam Map map){
        Query query = new Query(map);
        return backGroundService.selectBackGroundList(query);
    }

    @PostMapping("/add")
    @ResponseBody
    public R insetBackGround(@RequestParam Map map){

        backGroundService.insertBackGround(map);
        return R.ok();
    }

    @PostMapping("/update")
    @ResponseBody
    public R updateBackGround(@RequestParam Map map){
        backGroundService.updateBackGround(map);
        return R.ok();
    }

}
